home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1396 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: GoTo equivalent in C ??
  5. Date: Sat, 13 Jan 96 14:31:07 GMT
  6. Organization: none
  7. Message-ID: <821543467snz@genesis.demon.co.uk>
  8. References: <4d67vm$e5h@masala.cc.uh.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4d67vm$e5h@masala.cc.uh.edu> sukku@menudo.uh.edu "sukumar" writes:
  15.  
  16. >Hi,
  17. >        I have always thought about this. How do you get the effect of goto
  18. >in C without using "goto"?? For ex, if I have to check for an error in my
  19. >function for every computation I do, and then do some cleaning up, how do 
  20. >I do it. Here is an example:
  21.  
  22. Error handling is an area in C where using goto can be the best approach. 
  23. Early languages such as FORTRAN 66 gave you little choice but to use goto
  24. for many constructs. Then structured programming ideas became established
  25. and there were lots of compelling arguments (Dijkstra is a notable name here)
  26. as to why this is a much better approach than spaghetti code. However even
  27. Dijkstra accepted that goto still had its uses and, indeed, with discipline
  28. you can program in a structured way using goto.
  29.  
  30. >I don't want to use goto. what alternatievs do I have.
  31. >Any ideas are greatly appreciated.
  32.  
  33. Don't look for alternatives that make your code more complex and difficult
  34. to follow. To be sure you very rarely need to use goto but there are
  35. a few cases where the normal structured if/for/while/do constructs just can't
  36. model the problem sensibly.
  37.  
  38. -- 
  39. -----------------------------------------
  40. Lawrence Kirby | fred@genesis.demon.co.uk
  41. Wilts, England | 70734.126@compuserve.com
  42. -----------------------------------------
  43.